This is a document to learn how to use Rmarkdown.
So you can write normal text like this and when you knit it will show up like normal text.
you can also comment out things in the normal text like this
So first I will go over the header which is the top part of this code file.
There you will see and edit the title of the document, the author and the date. When creating a markdown file it will just leave it as the standard date but we found a code that will automatically update the date when you knit it so that is really handy. No more forgetting to change the date. The next part is the default output information. A newly created file will just have output: html_document. What is above is a way to customize the html more. So the css: is to tell it to use the code files to enable the use of the hide/show buttons (described later). toc = table of contents. So true = you want a table of contents, false would mean there wouldn’t be one. Depth is how many things will show up in the table. So right now it is at 2 so things with # or ## will show up in the table but not things with ### or more. You can change it to what you want. And then the floating means that in the html it will remain in the same spot on the side as you scroll instead of staying at the top of the page. That option is only available for the html. The code folding means that if you chose to print your code (instead of just the output) then it will be hidden and a button will show up to that you can click on to reveal the code.
You can knit you document into a word file or pdf but they are more finiky and less customizable so everyone in the lab generally sticks with the html. Although a pdf is easier to share with collaborators who do not use git hub.
With the normal text you can do formatting:
italics
bold
If with in the normal text you want to show code you can encase it in two backwards apostrophes: here()
You can also do code in the normal text - so when this is knitted it will show 8 and not the code function. 8
I have this sentence but there is not two spaces at the end of this. I have another sentence.
I have this sentence.
I have another sentence two spaces later.
sum(3+5) # sum
## [1] 8
sum(6+10)
## [1] 16
Here are some good websites with fancy stuff if you want
https://statr.me/2016/08/creating-pretty-documents-with-the-prettydoc-package/
I will just point out the two things that I use the most often.
this is great for condensing alot of things and it is really easy to implement. You simply put {.tabset} at the end of the title and then the next level down titles will be put into tabs.
Like so:
2*2
## [1] 4
2*3
## [1] 6
2*4
## [1] 8
2*5
## [1] 10
2*6
## [1] 12
Like so:
#this code chunk is named
It wont show up when knitted but if there is an error it will give the name of the code chunk (it also gives the line number of the first line of the code chunk that the error is in so its not that different). But it can help you find the chunk you need when things are collapsed.
Figure 1. Length of petals by species
Another fun and useful thing to do it to create interactive plots using the package plotly. You can integrate it with ggplot2 code as well.
Check out this webpage https://plotly.com/r/ for more information and ways to make your figure interactive. It can get real fancy haha!
library(plotly)
p <- plot_ly(iris, x = ~Sepal.Length, y = ~Petal.Length, color = ~Species, type = "scatter")
p